<template>
  <view class="hot-sale-section">
    <view class="section-header">
      <text class="section-title">{{ title }}</text>
      <view class="view-more" @click="onViewMore">
        <text>查看更多</text>
        <uni-icons type="right" size="14" color="#999"></uni-icons>
      </view>
    </view>
    
    <view class="product-grid">
      <view 
        class="product-item" 
        v-for="(item, index) in products" 
        :key="index"
        @click="onItemClick(item)"
      >
        <view class="rank-badge" v-if="showRank && index < 3">{{ index + 1 }}</view>
        <image :src="item.image" mode="aspectFill" class="product-image"></image>
        <view class="product-info">
          <text class="product-name">{{ item.name }}</text>
          <view class="product-price">
            <text class="price">¥{{ item.price }}</text>
            <text class="sales">已售{{ item.sales }}件</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'HotSaleSection',
  props: {
    title: {
      type: String,
      default: '热销商品'
    },
    products: {
      type: Array,
      default: () => []
    },
    moreUrl: {
      type: String,
      default: ''
    },
    showRank: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    onViewMore() {
      this.$emit('view-more')
    },
    onItemClick(item) {
      this.$emit('item-click', item)
    }
  }
}
</script>

<style lang="scss" scoped>
.hot-sale-section {
  background-color: #ffffff;
  border-radius: 12rpx;
  margin: 20rpx;
  padding: 20rpx;
  
  .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20rpx;
    
    .section-title {
      font-size: 32rpx;
      font-weight: bold;
      color: #333;
      position: relative;
      padding-left: 20rpx;
      
      &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 6rpx;
        height: 30rpx;
        background-color: #ff5500;
        border-radius: 3rpx;
      }
    }
    
    .view-more {
      display: flex;
      align-items: center;
      
      text {
        font-size: 24rpx;
        color: #999;
        margin-right: 4rpx;
      }
    }
  }
  
  .product-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20rpx;
    
    .product-item {
      background-color: #f8f8f8;
      border-radius: 8rpx;
      padding: 10rpx;
      position: relative;
      
      .rank-badge {
        position: absolute;
        top: 10rpx;
        left: 10rpx;
        width: 40rpx;
        height: 40rpx;
        background-color: #ff5500;
        color: #fff;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24rpx;
        font-weight: bold;
        z-index: 1;
      }
      
      .product-image {
        width: 100%;
        height: 300rpx;
        border-radius: 8rpx;
      }
      
      .product-info {
        padding: 10rpx 0;
        
        .product-name {
          font-size: 28rpx;
          color: #333;
          @include multi-ellipsis(2);
          height: 80rpx;
        }
        
        .product-price {
          display: flex;
          justify-content: space-between;
          align-items: center;
          margin-top: 10rpx;
          
          .price {
            font-size: 32rpx;
            color: #ff5500;
            font-weight: bold;
          }
          
          .sales {
            font-size: 22rpx;
            color: #999;
          }
        }
      }
    }
  }
}
</style> 